<?php
require_once 'lib/smarty/smarty.class.php';
session_start();
$smarty=new Smarty();
$mysqli = mysqli_connect("localhost","root","","aaa");
if($_POST){
	$email=$_POST['email'];
	$pwd=md5($_POST['pwd']);
	$sel_sql="select id from user where email='".$email."'";
	$result = $mysqli->query($sel_sql);
	$data=array();
	while($row = $result->fetch_assoc())
	{
		$data[] = $row;
	}
	if($data){
		//已经注册过了
		echo '1';
	}else{
		$sql="insert into user(email,pwd) values ('".$email."','".$pwd."')";
		$line = $mysqli->query($sql);
		if(!$line){
			//注册不成功
			echo '2';
		}else{
			//注册成功
			$_SESSION['aa_user']=array('id'=>$mysqli->insert_id,'email'=>$email,'pwd'=>$pwd);
			setcookie("aa_email",$email,time()+2*7*24*3600);
			setcookie("aa_pwd",$pwd,time()+2*7*24*3600);
			echo '3';
		}

	}
}else{
	$smarty->display('reg.html');
}